﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Com.GUI;
using Com.BU;
using Com.DA;
using ColdStorage.DOL;

namespace ColdStorage.GUI
{
    /// <summary>
    /// Interaction logic for ucRoomCold.xaml
    /// </summary>
    public partial class ucRoomCold : UserControl
    {
        private void ucRoom_Loaded(object sender, RoutedEventArgs e)
        {
           
            //loadRoomType();
            //loadProductName();                          
        }

        public ucRoomCold()
        {
            InitializeComponent();
            loadRoomColdInfo();
        }


        public void loadRoomColdInfo()
        {
            //Load Room Type
            cbxRoomType.Items.Clear();
            LibraryManagerInCom.loadRoomType();
            cbxRoomType.ItemsSource = LibraryManagerInCom.RoomTypeList;
            cbxRoomType.DisplayMemberPath = "storage_room";
            cbxRoomType.SelectedIndex = -1;

            // Load Product Name
            cbxInsideStorage.Items.Clear();
            LibraryManagerInCom.loadProduct();
            cbxInsideStorage.ItemsSource = LibraryManagerInCom.ProductList;
            cbxInsideStorage.DisplayMemberPath = "product_name";
            cbxInsideStorage.SelectedIndex = -1;

        }
      

        /// <summary>
        /// Delegate truyền dữ liệu Product ID qua cho product để lấy được enthalpy
        public delegate void GetProductId(int iProductId);
        public GetProductId MyProudctId;

        /// <summary>
        /// Deleegate truyen dữ liệu product type
        public delegate void GetProductType(int iProducttype);
        public GetProductType myProductType;
       
        
        
        private void cbxInsideStorage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                LibraryManagerInCom.loadProduct();
                LibraryManagerInCom.loadLoadingStandardList();
                tb_product product = (tb_product)cbxInsideStorage.SelectedItem;
                tb_loading_standard sd = LibraryManagerInCom.LoadingStandardList.SingleOrDefault
                   (s => s.product_id == product.id);
                txtLadingCoefficient.Text = sd.loading_standard.ToString();
            }
            catch(Exception ex)
            {
                MessageBox.Show("Chua co he so chat tai cho san pham nay");
                txtLadingCoefficient.Text = "";
            }

            LibraryManagerInCom.loadProduct();
            LibraryManagerInCom.loadLoadingStandardList();
            MyProudctId(((tb_product)cbxInsideStorage.SelectedItem).id);           
            myProductType(Convert.ToInt32(((tb_product)cbxInsideStorage.SelectedItem).product_type));

            

            ///truyền ID sản phẩm
            //MyProudctId(((tb_product)cbxInsideStorage.SelectedItem).id);
           // int iProductID = ((tb_product)cbxInsideStorage.SelectedItem).id;
           // MyProudctId(iProductID);                      
        }

        

        private void btnApply_Click(object sender, RoutedEventArgs e)
        {
           

            //ucProduct ucProduct = new ucProduct();
            //ucProduct.GetStringFromAnotherForm += delegate { return txtroomHeight.Text; };

            ///truyền ID sản phẩm


            try
            {

                Room rRoom = new Room();
                rRoom.dbRoomHeight = Convert.ToDouble(txtroomHeight.Text);
                rRoom.dbRoomWidth = Convert.ToDouble(txtroomWidth.Text);
                rRoom.dbRoomLength = Convert.ToDouble(txtroomLenght.Text);
                rRoom.dbRoomLadingCoefficient = Convert.ToDouble(txtLadingCoefficient.Text);


                rRoom.CalculateRoomVolume();
                txtroomCapacity.Text = rRoom.CalculateRoomCapacity().ToString();
                rRoom.dbRoomCapacity = Convert.ToDouble(txtroomCapacity.Text);


            }
            catch (Exception ex)
            {

                MessageBox.Show("Chua du thong tin de tinh capacity");
            }
            
              
            
            
            
            //int iProductID = ((tb_product)cbxInsideStorage.SelectedItem).id;
            //MyProudctId(iProductID);

        }

       
        


        

        

    }
}
